<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<meta http-equiv="Pragma" content="no-cache"> 
<meta http-equiv="Cache-Control" content="no-cache"> 
<meta http-equiv="Expires" content="0"> 
<title>知文招标网 - 后台管理</title>
<link rel="short icon" href="../front/images/28.jpg">
<link href="css/login.css" type="text/css" rel="stylesheet"> 
</head> 
<body> 

<div class="login">
    <div class="message">知文招标网-管理员登录</div>
    <div id="darkbannerwrap"></div>
    <form id="myform">
		<hr class="hr15">
		<input name="username" id="username" placeholder="账号" required type="text"  @blur="blur(1)">
		<span style="color:red;display:none" class="nameWarn">账号提示</span>
		<hr class="hr15">
		<input name="password" id="pwd" placeholder="密码" required type="password"  @blur="blur(2)" @keyup.enter="userLogin">
		<span style="color:red;display:none" class="pwdWarn">密码提示</span>
		<hr class="hr15">
		<span id="waring-info" style="color:red"></span>
		<hr class="hr15">
		<input value="登录" style="width:100%;" type="button" @click="userLogin">
		<hr class="hr20">
	</form>
	<div id="adminOp">
		<a href="manager/pwd.html">忘记密码</a>
<!--		<a href="manager/reg.html">注册账号</a>-->
	</div>
</div>

<div class="copyright">湖南省岳阳市知文招标有限公司</a> &copy; 版权所有 &copy; 后台管理系统</div>

<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="js/vue.js"></script>
<script type="text/javascript" src="js/axios.js"></script>
<script type="text/javascript" src="js/qs.js"></script>
<script type="text/javascript" src="js/show-dialog.js"></script>
<script type="text/javascript" src="js/stringCheckNull.js"></script>
<script type="text/javascript">
$(function(){
	let userName = localStorage.getItem("userName");
	let userId = localStorage.getItem("userId");
	let notLogin = isEmpty(userId)
	//有记录直接登录  没有则需要登录
	if(!notLogin){
		location.href="manager/index.html"
	}
	
	$("#myform input").focus(function(){
		$(this).removeClass("navy_error");
		$("#waring-info").text("");
	})

});

let loginPage = new Vue({
	el:".login",
	data:{
	},
	methods:{
		blur(index){
			let userName = $.trim($("#username").val());
			let pwd = $.trim($("#pwd").val());
			//账号失焦
			if(index == 1){
				if(userName.length < 3 || userName.length > 20){
					$(".nameWarn").css("display",'block')
					$(".nameWarn").text("账号长度为3-20位")
					return
				}else if(userName.length <= 0){
					$(".nameWarn").css("display",'block')
					$(".nameWarn").text("请输入账号")
				}else{
					$(".nameWarn").css("display",'none')
				}
			}
			//密码失焦
			if(index == 2){
				if(pwd.length < 6 || pwd.length > 16){
					$(".pwdWarn").css("display",'block')
					$(".pwdWarn").text("密码长度为6-16位")
					return
				}else if(pwd.length <= 0){
					$(".pwdWarn").css("display",'block')
					$(".pwdWarn").text("密码不能为空")
					return
				}else{
					$(".pwdWarn").css("display",'none')
				}
			}
		},
		userLogin(){
			let userName = $.trim($("#username").val());
			let pwd = $.trim($("#pwd").val());
			if (isEmpty(userName) || isEmpty(pwd)) {
				return;
			}
			let nameFlag = ($(".nameWarn").css("display") == "none")
			let pwdFlag = ($(".pwdWarn").css("display") == "none")
			if(!nameFlag || !pwdFlag){
				return;
			}
		
			$.post("/user/login", {userName:userName, pwd:pwd}, rt => {
				console.log(rt)
				if (rt.code == 200) {
					showmsg("登陆成功,正在跳转","green",function(){
						let userId = rt.data.id;
						let userName = rt.data.userName;
						localStorage.setItem("userId",userId)
						localStorage.setItem("userName",userName)
						location.href="manager/index.html";
						return;
					})
				}else{
					showmsg("您输入的账号或密码有误,请重试...","red")
				}
				
			}, "json");
		}
	},
	mounted(){
		
	}
})

</script>
</body>
</html>